package com.atguigu.day11.exer.e3;

/**
 * @version 1.0
 * @Author 马冰
 * @Date 2024/11/12 16:28
 * @注释
 */
public class Triangle {
    private final double a, b, c;
    public Triangle(double a, double b, double c) {
        if (a > 0 && b > 0 && c > 0 && a + b > c && b + c > a && a + c > b && b + c > a) {
            this.a = a;
            this.b = b;
            this.c = c;
        }else{
            this.a = 0;
            this.b = 0;
            this.c = 0;
            System.out.println("边长输入错误，无法组成三角形");
        }
    }

    public double getA() {
        return a;
    }

    public double getB() {
        return b;
    }

    public double getC() {
        return c;
    }

    public double area() {
        double p = (a + b + c) / 2;
        return Math.sqrt(p * (p - a) * (p - b) * (p - c));
    }
    public double perimeter() {
        return a + b + c;
    }

    @Override
    public String toString() {
        return "三角形的三条边是：" + a + "," + b + "," + c + ",面积是：" + area() + "周长是：" + perimeter();
    }
}
